#include "Buddy.h"
#include <time.h>
#include <math.h>
#include <stdio.h>


int main()
{
	srand(time(0));
	
	struct mem_pool *pool = CreatePool(1024);
		
	void *ptr1 = Alloc(pool,50);
	void *ptr2 = Alloc(pool,50);
	void *ptr3 = Alloc(pool,50);
	void *ptr4 = Alloc(pool,50);
	void *ptr5 = Alloc(pool,50);
	void *ptr6 = Alloc(pool,50);
	void *ptr7 = Alloc(pool,50);
	void *ptr8 = Alloc(pool,50);
	void *ptr9 = Alloc(pool,50);
	void *ptr10 = Alloc(pool,50);
	
	void *array[10] = {ptr1,ptr2,ptr3,ptr4,ptr5,ptr6,ptr7,ptr8,ptr9,ptr10};
	int size = 10;
	int i = 0;
	int indexs[10] = {0,1,2,3,4,5,6,7,8,9};
	int tmp[10];
	for( ; i < 10; ++i)
	{
		int index = rand()%size;
		tmp[i] = indexs[index];
		indexs[index]= indexs[size-1];
		--size;
	}	
	for(i = 0; i < 10; ++i)
	{
		Free(pool,array[tmp[i]]);
		//Free(pool,array[i]);
	}
	printf("%d\n",GetPoolSize(pool));
	

	DestroyPool(&pool);		
	return 0;
	
}